@extends('admin_system.layout.layout')
@section('content')
    <!--suppress ALL -->
    <br>
    <div class="container">
        <div class="list-group">
            <a href="#" class="list-group-item active">
                <h4 class="list-group-item-heading">学习官那点事</h4>
                <p class="list-group-item-text">添加文章</p>
            </a>
        </div>

        <div class="panel panel-default">
            <div class="panel-body">
                <form action="{{route('article_save')}}" method="post" id="articel_save" enctype="multipart/form-data">
                    {{csrf_field()}}
                    <div class="form-group">
                        <label for="title" class="control-label">文章的标题:</label>
                        <div class="">
                            <input type="title" name="title" id="title" class="form-control" value="" required="required">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="article_img" class="control-label">文章图片:</label>
                        <div class="">
                            <input type="file" name="article_img" id="article_img" class="form-control" value="">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="lessons_category_id" class="control-label">分类:</label>
                        <div class="">
                            <select name="lessons_category_id" id="lessons_category_id" class="form-control">
                                <option value="1">文章</option>
                                <option value="2">视频</option>
                            </select>
                        </div>
                    </div>
                    <div id="editor">
                        <p>文章的内容</p>
                    </div>
                    <input type="hidden" id="body" name="body">
                    <br>

                    <div id="editor_1">
                        <p>内容介绍</p>
                    </div>
                    <input type="hidden" id="introduce" name="introduce">

                    <div class="clearfix"></div>
                    <br>
                    <button type="button" class="btn btn-info" id="article_save" style="width: 100%">保存</button>
                </form>
            </div>
        </div>
    </div>
    <script src="{{asset('admin/js/wangEditor.min.js')}}"></script>
    <script type="text/javascript">
        $(function () {
            var E = window.wangEditor
            var editor = new E('#editor')
            var editor_1 = new E('#editor_1')
            editor.customConfig.uploadImgServer = '{{route('article_img_upload')}}';

            editor.customConfig.uploadImgMaxLength = 1;
            // 将图片大小限制为 3M
            editor.customConfig.uploadImgMaxSize = 3 * 1024 * 1024;

            editor.customConfig.uploadImgParams = {
                _token: "{{csrf_token()}}"   // 属性值会自动进行 encode ，此处无需 encode
            }


            editor.customConfig.customAlert = function (info) {
                swal("Oops!", ""+info+"!", "error")
            }

            editor.customConfig.uploadFileName = 'article_content_img';

            editor_1.customConfig.menus = []

            editor.create()
            editor_1.create()


            $('#article_save').on('click', function () {
                $('#body').val(editor.txt.html());
                $('#introduce').val(editor_1.txt.text());
                document.getElementById('articel_save').submit();
            })

        })

    </script>
@stop